package javafx;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import model.Classe;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.CustomNode;
import javafx.scene.layout.Flow;
import javafx.scene.text.TextOrigin;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.stage.Screen;
import fachada.Fachada;

/**
 * @author Henrique Fernandes
 */

/*Declaracao de variaveis globais a esta classe*/
var rect:Rectangle;
var font:Font;
var text:Text;

/*fim das declaracoes*/

/**
*Classe que responsavel pela parte estatica
*do diagrama de classes.
*/
public class ClassesEstaticas extends CustomNode{

    public var largura = Screen.primary.visualBounds.width;
    public var altura = Screen.primary.visualBounds.height - 250;
    public var colecaoClasses:Classe[];

    /**
    *Funcao responsavel por criar o formato das classes e textos
    *dinamicamente. Todos os retangulos sao criados juntamente com
    *os textos usando um Group.
    *Todos os Groups sao alinhados atraves do container Flow, que e
    *responsavel por alinha-los.
    *
    *@return Container com as classes criadas.
    */
    public override function create(): Node {
        return Flow {
            layoutX: 20 layoutY: 70
            width: largura;
            height: altura;
            hgap: 5 vgap: 5
            content:[
                for(classe in colecaoClasses) {
                    Group{
                        content:[
                            rect = Rectangle {
                                width: classe.getNome().length() * 10;
                                height: 120;
                                fill: LinearGradient {
                                    startX: 0, endX: 0, startY: 0, endY: 1
                                    stops: [
                                        Stop { offset: 0.0 color: Color.web("#dceaff")},
                                        Stop { offset: 0.49 color: Color.web("#6885b2") }
                                        //Stop { offset: 0, color: Color.rgb(202, 202, 202) }
                                        //Stop { offset: 1, color: Color.rgb(97, 97, 97) }
                                    ]
                                }
                                stroke: Color.BLACK;
                                arcHeight: 10;
                                arcWidth: 10;
                                strokeWidth: 2;
                                cursor: Cursor.HAND;
                            }
                            text = Text {
                                font : font = Font { size:17;  embolden:true; }
                                //translateX: bind (rect.layoutX + (rect.width/2)) - (text.layoutBounds.width/2)
                                translateX: bind rect.layoutX;
                                textOrigin: TextOrigin.TOP;
                                content: classe.getNome().trim();
                                //content: bind classe.toString();
                            }
                            /*label = Label{
                                font: font = Font { size: 18 embolden:true }
                                text:classe.getNome().trim();
                                translateX: bind (rect.layoutX + (rect.width/2)) - (label.layoutBounds.width/2)
                            }*/
                        ]
                    }
                }
            ]
        };
    }
}
